//------------------------------------------------------------------
//
// @@@ START COPYRIGHT @@@
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.
//
// @@@ END COPYRIGHT @@@

//
// Implement map and thread-safe map
//

#ifndef __SB_MAPSTATS_H_
#define __SB_MAPSTATS_H_

#include <stdio.h>

#include "seabed/int/opts.h"

#include "seabed/thread.h"

#ifdef USE_SB_MAP_STATS
class SB_Map_Stats {
public:
    SB_Map_Stats(void       *pp_map,
                 const char *pp_map_type,
                 const char *pp_map_name,
                 int         pv_buckets);
    virtual ~SB_Map_Stats();

    int  chain_add(int pv_hash);
    void chain_del(int pv_hash);
    void print_stats();
    void resize(int pv_buckets);

private:
    static FILE           *cp_file;
    static SB_Thread::MSL *cp_lock;         // for protection

    int                   *ip_bucket_len;
    int                   *ip_bucket_max;
    void                  *ip_map;
    const char            *ip_map_type;
    const char            *ip_map_name;
    int                    iv_buckets;
    int                    iv_count;
    int                    iv_count_max;
};

#ifdef USE_SB_INLINE
#include "mapstats.inl"
#endif

#endif

#endif // !__SB_MAPSTATS_H_

